package py.edu.ucom.cadira.net.serializables;

import org.jdom.Document;
import org.jdom.Element;

import py.edu.ucom.cadira.net.XMLSerializable;

public class StandarRequest implements XMLSerializable { 
	
	private TYPE TypeRequest;
	
	public StandarRequest(TYPE typeRequest) {
		TypeRequest = typeRequest;
	}
	
	public StandarRequest(){
		
	}
	public static enum TYPE {
		LIST_TABLES,
		CREATE_TABLE,
        STAR_GAME;
	}

	public TYPE getTypeRequest() {
		return TypeRequest;
	}

	public void setTypeRequest(TYPE typeRequest) {
		TypeRequest = typeRequest;
	}
	public void fromXML(Document xml) {
		
		Element root = xml.getRootElement();
		Element joinTableNode = root.getChild("listMesas");
		String requestTypeStr = joinTableNode.getAttribute("requestType").getValue();
		TYPE typeValue = TYPE.valueOf(requestTypeStr);
		setTypeRequest(typeValue);
		
	}

	public void toXML(Element root) {
		
		Element joinTableNode = new Element("listMesas");
		joinTableNode.setAttribute("requestType",getTypeRequest().toString());
		root.addContent(joinTableNode);
		
	}
	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof StandarRequest)) {
			return false;
		}
		StandarRequest otherObj = (StandarRequest) obj;
		if (otherObj.getTypeRequest() == getTypeRequest()) {
			return true;
		}
		return false;
	}
}
